﻿/* Copyright SysMates Technologies Pte. Ltd. */
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Text.RegularExpressions;
using AppPressFramework;
using System.Globalization;
using System.Resources;
using AppPressFramework;
using ApplicationClasses;

namespace Application
{

    public partial class AppLogic
    {
        public static void Init(AppPress a, ApplicationMasterClass ApplicationMaster)
        {
            var loginUserId = a.sessionData.loginUserId;
            ApplicationMaster.Name.val = a.ExecuteString("Select Name From Application_Users Where Id = " + loginUserId);
        }

        public static void Init(AppPress a, AdminMenusExtensionClass AdminMenus)
        {
            var isAdmin = ((AppSessionData)a.sessionData).isAdmin;
            if (!isAdmin)
            {
                AdminMenus.UserManagement.Hidden = FieldHiddenType.Hidden;
            }
        }

        public static void Calc(AppPress a, ApplicationMasterClass.TitleFieldClass Title)
        {
            if (Title.FormData.Content.val.Count > 0)
                Title.val = AppPress.InsertSpacesBetweenCaps(Title.FormData.Content.val[0].GetFormName());
        }
        public static void Calc(AppPress a, BlankMasterClass.TitleFieldClass Title)
        {
            if (Title.FormData.Content.val.Count > 0)
                Title.val = AppPress.InsertSpacesBetweenCaps(Title.FormData.Content.val[0].GetFormName());
        }

        public static void OnClick(AppPress a, AdminMenusExtensionClass.UserManagementFieldClass UserManagement)
        {
            UserManagementClass.Redirect(a, null, null);
        }
        public static void OnClick(AppPress a, ApplicationMenusExtensionClass.HomeFieldClass Home)
        {
            HomeClass.Redirect(a, a.sessionData.loginUserId.ToString(), null);
        }
        public static void OnClick(AppPress a, ApplicationMasterClass.ChangePasswordFieldClass ChangePassword)
        {
            var loginUserId = a.sessionData.loginUserId;
            ChangePasswordClass.Popup(a, loginUserId, null);
        }
        public static void OnClick(AppPress a, ApplicationMenusExtensionClass.SignoutFieldClass Signout)
        {
            HttpContext.Current.Session.Clear();
            HttpContext.Current.Session.Abandon();
            var redirectParams = new RedirectParams();
            redirectParams.postParams.Add("FromSignout", "");

            // delete cookiesfGetMeth
            var emailCookie = a.Response.Cookies[CookiePreix(a) + "Email"];
            emailCookie.Expires = DateTime.Now.AddDays(-1);
            a.Response.Cookies.Add(emailCookie);
            var passwordCookie = a.Response.Cookies[CookiePreix(a) + "Password"];
            passwordCookie.Expires = DateTime.Now.AddDays(-1);
            a.Response.Cookies.Add(passwordCookie);
            //Signout.FormData.SaveAndUpdateUI
            LoginClass.Redirect(a, null, null);
        }
        public static List<FormData> Domain(AppPress a, ApplicationMasterClass.ContentFieldClass Content)
        {
            return Content.GetMasterContainer(a);
        }
        public static List<FormData> Domain(AppPress a, BlankMasterClass.ContentFieldClass Content)
        {
            return Content.GetMasterContainer(a);
        }

    }
}